<?php
class Mwc_SystemPoint_Block_Userpoint_Main_Grid extends Mage_Adminhtml_Block_Widget_Grid{
    public function __construct(){
        parent::__construct();
        $this->setId('userpointGrid');
        $this->_controller = 'systempoint';
    } 
 
    protected function _prepareCollection(){
        $model = Mage::getModel('systempoint/userpoint');
        $collection = $model->getCollection();
		$this->setCollection($collection);
        return parent::_prepareCollection();
    }
 
    protected function _prepareColumns(){ 
    	$model = Mage::getModel('systempoint/userpoint')->getCollection();
    	$model->getSelect()->group('group_title');
		    foreach($model as $item){
	            $catArr[] = $item->getGroupTitle();
	        }
        $this->addColumn('userpoint_id', array(
            'header'        => Mage::helper('systempoint')->__('ID'),
            'align'         => 'right',
            'width'         => '50px',
            'filter'        => false,
            'sortable'      => false,
            'index'         => 'userpoint_id',
        ));
 
        $this->addColumn('email', array(
            'header'        => Mage::helper('systempoint')->__('Email'),
            'align'         => 'left',
            'width'         => '200px',
            'filter_index'  => 'email',
            'index'         => 'email',            
        ));
 
        $this->addColumn('group_title', array(
            'header'    	=> Mage::helper('systempoint')->__('Group'),
            'align'         => 'left',
            'filter_index'  => 'group_title',
            'index'    	 	=> 'group_title',       
//        	'type'			=> 'options',    
//			'options' 		=> $catArr,   
        ));
 
        $this->addColumn('shadow_point', array(
            'header'        => Mage::helper('systempoint')->__('Shadow point'),
            'align'         => 'left',
            'filter_index'  => 'shadow_point',
            'index'         => 'shadow_point',
        ));
 
		$this->addColumn('ordered_point', array(
            'header'        => Mage::helper('systempoint')->__('Ordered point'),
            'align'         => 'left',
            'filter_index'  => 'ordered_point',
            'index'         => 'ordered_point',
        ));
        
		$this->addColumn('shared_point', array(
            'header'        => Mage::helper('systempoint')->__('Point by shared'),
            'align'         => 'left',
            'filter_index'  => 'shared_point',
            'index'         => 'shared_point',
        ));
        
		$this->addColumn('user_point', array(
            'header'        => Mage::helper('systempoint')->__('Point'),
            'align'         => 'left',
            'filter_index'  => 'user_point',
            'index'         => 'user_point',
        ));
        
		/*$this->addColumn('add_date', array(
            'header'        => Mage::helper('systempoint')->__('Date add point'),
            'align'         => 'left',
            'filter_index'  => 'add_date',
            'index'         => 'add_date',
            'filter'        => false,
            'sortable'      => false,
        ));      
        
		$this->addColumn('exp_date', array(
            'header'        => Mage::helper('systempoint')->__('Expire date'),
            'align'         => 'left',
            'filter_index'  => 'exp_date',
            'index'         => 'exp_date',
            'filter'        => false,
            'sortable'      => false,
        )); */                                                                    
		
        $this->addColumn('action',
            array(
                'header'    => Mage::helper('systempoint')->__('Action'),
                'width'     => '150px',
                'type'      => 'action',
                'getter'	=> 'getUserpointId',
                'actions'   => array(
                    array(
                        'caption' => Mage::helper('systempoint')->__('Edit'),
                        'url'     => array(
							'base'=>'*/*/edit'
                        ),
                        'field'   => 'id'
                    ),
                    array(
                        'caption' => Mage::helper('systempoint')->__('Delete'),
                        'url'     => array(
                            'base'=>'*/*/delete'
                        ),
                        'field'   => 'id'
                    )
                ),
                'filter'    => false,
                'sortable'  => false
        ));
 
        return parent::_prepareColumns();
    }
 
    public function getRowUrl($row){
        return $this->getUrl('*/*/edit', array(
            'id' => $row->getUserpointId(),
        ));
    }
}